/*
 * main.cpp
 *
 * Implementacia vstupneho bodu aplikacie
 *
 *  Created on: 1.4.2011
 *      Author: Tomas Srna
 */

#include "main.h"

int main (int argc, char ** argv)
{
#ifdef TEST
	// Test: Filesystem
	FileFS fs("tftproot");
	IFileTest ftfs(fs, cout);
	if(!ftfs.run())
		return 1;
	// Minitest: TAR
	FileTAR ft("tftproot.tar");
	const unsigned int bs = 3546546;
	try
	{
		ft.open("tomas.jpg", "r");
		fs.open("tomas.jpg", "w");
		while(!ft.eof())
		{
			char buf [bs];
			unsigned int r = ft.read(buf, bs);
			fs.write(buf, r);
		}
		// Test hladania suborov
		ft.open("test3", "r");
		ft.open("test1", "r");
		ft.close();
	}
	catch (const char * e)
	{
		cout << "Chyba: " << e << endl;
	}
	// Test: TAR
	IFileTest fttar(ft, cout);
	fttar.run();
	// Test: Packet
	cout << "Testing Packet" << endl;
	cout << " - synthesis: ";
	Packet p;
	p.opcode = Packet::RRQ;
	p.filename = "a.txt";
	p.mode = "netascii";
	p.print(cout);
	cout << endl;
	vector<char> v1, v2;
	p.store(v1);
	cout << " - analysis:  ";
	Packet q(&v1[0], v1.size());
	cout << "Type: " << q.opcode << "; Filename: " << q.filename
			<< "; Mode: " << q.mode << endl;
	cout << " - match:     ";
	q.store(v2);
	if(v1.size() != v2.size() || !equal(v1.begin(), v1.end(), v2.begin()))
		cout << "[fail]" << endl;
	else
		cout << "[ok]" << endl;
	cout << "--[End of tests]---------------------------------------------------------------------------------------------" << endl;
#endif /* TEST */
	return Runner::run(argc, argv);
}
